package ar.com.drconta.ganancias.editors.example;

import java.util.List;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import ar.com.drconta.ganancias.editors.example.modelVO.Category;
import ar.com.drconta.ganancias.editors.example.modelVO.City;
import ar.com.drconta.ganancias.editors.example.modelVO.House;
import ar.com.drconta.ganancias.editors.example.modelVO.Item;
import ar.com.drconta.ganancias.editors.example.modelVO.PersonFolder;
import ar.com.drconta.ganancias.editors.example.modelVO.Street;

class FoldersContentProvider implements ITreeContentProvider{
      /**
	 * 
	 */
	private View AddressContentProvider;

	/**
	 * @param view
	 */
	FoldersContentProvider(View view) {
		AddressContentProvider = view;
	}

	public Object[] getChildren(Object parentElement){
         if (parentElement instanceof List)
            return ((List<?>) parentElement).toArray();
         if (parentElement instanceof PersonFolder)
        	 return ((PersonFolder) parentElement).getCategories().toArray();
         if (parentElement instanceof Category)
            return ((Category) parentElement).getRows().toArray();
         return new Object[0];
      }
 
      public Object getParent(Object element){
         if (element instanceof Category)
            return ((Category) element).getParent();
         if (element instanceof Item)
            return ((Item) element).getParent();
         return null;
      }
 
      public boolean hasChildren(Object element){
         if (element instanceof List)
            return ((List<?>) element).size() > 0;
         if (element instanceof PersonFolder)
            return ((PersonFolder) element).getCategories().size() > 0;
         if (element instanceof Category)
            return ((Category) element).getRows().size() > 0;
         return false;
      }
 
      public Object[] getElements(Object folder){
         // cities ist das, was oben in setInput(..) gesetzt wurde.
         return getChildren(folder);
      }
 
      public void dispose(){
      }
 
      public void inputChanged(Viewer viewer, Object oldInput, Object newInput){
      }
   }